import Content from '@/sheep/layouts/content.vue';
import { request } from '@/sheep/request';
import { CRUD, RECYCLE } from '@/sheep/request/crud';

const route = {
  path: 'app',
  name: 'shop.admin.app',
  component: Content,
  meta: {
    title: '应用',
  },
  children: [
    {
      path: 'scoreshop',
      name: 'shop.admin.app.scoreshop',
      component: () => import('./scoreShop/index.vue'),
      meta: {
        title: '积分商城',
      },
    },
    {
      path: 'mplive',
      name: 'shop.admin.app.mplive',
      component: () => import('./mplive/index.vue'),
      meta: {
        title: '小程序直播',
      },
    },
  ],
};

const api = {
  scoreShop: {
    ...CRUD('shop/admin/app/scoreShop', ['list', 'add', 'edit', 'delete']),
    ...RECYCLE('shop/admin/app/scoreShop'),
    getSkuPrices: (id) =>
      request({
        url: '/shop/admin/app/scoreShop/skuPrices/' + id,
        method: 'GET',
      }),
    skus: (id) =>
      request({
        url: `/shop/admin/app/scoreShop/skus/${id}`,
        method: 'GET',
      }),
    select: (params, type = 'page') =>
      request({
        url: `shop/admin/app/scoreShop/select?type=${type}`,
        method: 'GET',
        params,
      }),
  },
  mplive: {
    room: {
      ...CRUD('shop/admin/app/mplive/room', ['list', 'detail', 'delete']),
      add: (data) =>
        request({
          url: '/shop/admin/app/mplive/room',
          method: 'POST',
          timeout: 80000,
          data,
        }),
      edit: (id, data) =>
        request({
          url: '/shop/admin/app/mplive/room/' + id,
          method: 'PUT',
          timeout: 80000,
          data,
        }),
      select: (params) =>
        request({
          url: `shop/admin/app/mplive/room/select`,
          method: 'GET',
          params,
        }),
      sync: () =>
        request({
          url: '/shop/admin/app/mplive/room/sync',
          method: 'GET',
        }),
      pushUrl: (id) =>
        request({
          url: '/shop/admin/app/mplive/room/pushUrl/' + id,
          method: 'GET',
        }),
      qrcode: (id) =>
        request({
          url: '/shop/admin/app/mplive/room/qrcode/' + id,
          method: 'GET',
        }),
      playback: (id) =>
        request({
          url: '/shop/admin/app/mplive/room/playback/' + id,
          method: 'GET',
        }),
    },
    goods: {
      ...CRUD('shop/admin/app/mplive/goods', ['list', 'detail', 'delete']),
      add: (data) =>
        request({
          url: '/shop/admin/app/mplive/goods',
          method: 'POST',
          timeout: 80000,
          data,
        }),
      edit: (id, data) =>
        request({
          url: '/shop/admin/app/mplive/goods/' + id,
          method: 'PUT',
          timeout: 80000,
          data,
        }),
      audit: (id, data) =>
        request({
          url: '/shop/admin/app/mplive/goods/audit/' + id,
          method: 'POST',
          data,
        }),
      status: (id) =>
        request({
          url: '/shop/admin/app/mplive/goods/status/' + id,
          method: 'GET',
        }),
    }
  },
};

export { route, api };
